package paydayTransaction;

import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import database.PayrollDatabase;

import addEmployeeTransaction.Employee;

import main.Transaction;
import main.Paycheck;

public class PaydayTransaction extends Transaction {
	private Date date;
	private Hashtable<Integer, Paycheck> paychecks = new Hashtable<Integer, Paycheck>();

	public PaydayTransaction(Date date, PayrollDatabase database) {
		super(database);
		this.date = date;
	}

	@Override
	public void execute() {
		ArrayList<Integer> empIds = database.getAllEmployeeIds();		
		for (int empId : empIds) {
			Employee e = database.getEmployee(empId);
			
			if (e.isPayDate(date)) {
				
				Date startDate = e.getPayPeriodStartDate(date);
				
				Paycheck pc = new Paycheck(startDate, date);	
				paychecks.put(empId, pc);
				e.payday(pc);
			}
		}
	}

	public Paycheck getPaycheck(int empId) {
		return paychecks.get(empId);
	}
}
